package com.bcx.controller;

import com.bcx.pojo.Air;
import com.bcx.service.AirService;
import com.bcx.tool.ResultEntity;
import com.github.pagehelper.PageInfo;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class AirController {
    @Resource
    AirService airService;
    @RequestMapping("selectAir")
    public ResultEntity<PageInfo<Air>> selectAir(@RequestParam(value = "districtid",required =false ,defaultValue = "0") Integer districtid,
                                                 @RequestParam(value = "pageNum",required = false,defaultValue = "1")Integer pageNum
    ){
        PageInfo<Air> pageInfo =airService.selectAll(districtid,pageNum);
        return ResultEntity.successWithoutData(pageInfo);
    }
    @RequestMapping("/saveAir")
    public ResultEntity<String> saveAir(@RequestBody Air air){
        try {
            Integer integer=0;
            if (air.getId()==null){
                integer=airService.insert(air);
            }else{
                integer=airService.update(air);
            }
            return ResultEntity.successWithoutData(integer+"");
        }catch (Exception ex){
            return ResultEntity.failed(ex.getMessage());
        }
    }
    @RequestMapping("/getAirById")
    public ResultEntity<Air> getAirById(Integer id){
        Air air=airService.getById(id);
        return ResultEntity.successWithoutData(air);
    }
    @RequestMapping("/delAirById")
    public ResultEntity<String> delAirById(Integer id){
        try {
            Integer integer=airService.delete(id);
            return ResultEntity.successWithoutData(integer+"");
        }catch (Exception ex){
            return ResultEntity.failed(ex.getMessage());
        }
    }
}
